package com.example.demo.day0301;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;

public class BufferedCopyFile1 {
    public static void main(String[] args) {
        try {
            BufferedCopyFile1.testBufferedCopyFile1();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    public static void testBufferedCopyFile1() throws Exception {
        BufferedReader br = new BufferedReader(new FileReader("D:\\demo\\src\\main\\java\\com\\example\\demo\\day0301\\tt3.txt"));
        //缓冲字符输入流

        BufferedWriter bw = new BufferedWriter(new FileWriter("D:\\demo\\src\\main\\java\\com\\example\\demo\\day0301\\tt4.txt"));
        //缓冲字节输出流

        char[] c = new char[100];//缓冲数组
        int len = 0;

        while((len = br.read(c)) != -1) {//直到br.read执行到没有字符串，此时返回值为-1。不再读取文件
            bw.write(c, 0, len);//写到内存中
        }
        bw.flush();//刷到硬盘
        bw.close();
        br.close();//先开后关
    }
}
